﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FPPrinter.Models.Printers
{
    public static class Ex
    {
        public static Printer FirstOrEmpty(this IEnumerable<Printer> printers,
            Func<Printer, bool> predicate)
        {
            var res = printers.FirstOrDefault(predicate);
            if (res != null) res = Printer.OfEmpty();
            return res;
        }

        public static IPrinter FirstOrEmpty(this IEnumerable<IPrinter> printers,
            Func<IPrinter, bool> predicate)
        {
            var res = printers.FirstOrDefault(predicate);
            if (res == null) res = Printer.OfEmpty();
            return res;
        }
    }
}